var mongoose=require('mongoose');
var Book=mongoose.model('Book',{
    name:String,
    time:Date,
    price:Number
});
var db=mongoose.connect('mongodb://localhost/MongoDB_QuanWei_2');


Book.update({name:'B1'},{time:new Date(2016,3,1),price:'12'},{upsert:true},(e,r)=>{
    if(e)throw e;
    console.log('Update:\n',r);

    Book.update({name:'B2'},{time:new Date(2016,4,1),price:'12.00'},{upsert:true},(e,r)=>{
        if(e)throw e;
        console.log('Update:\n',r);


        Book.update({name:'B3'},{time:new Date(2016,5,1),price:'abcd'},{upsert:true},(e,r)=>{
            if(e)throw e;
            console.log('Update:\n',r);

            Book.update({name:'B4'},{time:new Date(2016,6,1),price:undefined},{upsert:true},(e,r)=>{
                if(e)throw e;
                console.log('Update:\n',r);

                Book.find({


                },(e,books)=>{
                    if(e)throw e;
                    //console.log('\nFind:\n',JSON.stringify(r,null,2));
                    books.forEach((book)=>{
                        console.log(book.time,Object.prototype.toString.call(book.time));
                    });
                    process.exit(1);
                });


            });

        });

    });

});


/*
* {field:{$mod:[除数，余数]}
*
* 匹配field值取模运算结果
* */
